package com.example.chatroom.handler;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.socket.*;
import org.springframework.web.socket.handler.TextWebSocketHandler;

@ComponentScan
public class MessageHandler extends TextWebSocketHandler {
    @Override
    protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
        System.out.println("I am the handleTextMessage!");
        super.handleTextMessage(session, message);
    }

//    客户端发起请求时候调用
    @Override
    public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
        System.out.println("I am the handleMessage!");
        super.handleMessage(session, message);
    }
//    WebSocket建立连接后调用
    @Override
    public void afterConnectionEstablished(WebSocketSession session) throws Exception {
        System.out.println("I am the afterConnectionEstablished!");
        super.afterConnectionEstablished(session);
    }
//    WebSocket关闭连接时调用
    @Override
    public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
        System.out.println("I am the afterConnectionClosed!");
        super.afterConnectionClosed(session, status);
    }

    @Override
    protected void handlePongMessage(WebSocketSession session, PongMessage message) throws Exception {
        System.out.println("I am the handlePongMessage!");
        super.handlePongMessage(session, message);
    }
//    处理传输过程中出错时调用
    @Override
    public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
        System.out.println("I am the handleTransportError!");
        super.handleTransportError(session, exception);
    }
}
